<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <title></title>
        <#include "/inc/head.ftl"/>
    	<@head/> 
</head>
<body>
            <div class="panel panel-default">
                <div class="panel-body">
                    <div class="row">
						<div class="col-lg-12">
                            <form id="form" action="${contextPath}/orderform/register" method="post">
                            <div>
                                <input id="control" name="control" type="hidden" value="" class="form-control">
                                
                                <div class="form-group">
                                    <label>订单编号</label>
                                    <input id="orderformNumber"   name="orderform.orderformNumber" value="${(orderformNumber)!}" class="form-control" readonly="readonly">
                                </div>
              
                                <div class="form-group">
                                    <label>客户</label>
                                    <select id="customerId"  name="orderform.customerId"  class="form-control">
                                    </select>
                                </div>
                                
                                <div class="form-group">
                                    <label>收银员</label>
                                    <input id="userName"   name="login.userName" value="${(login.userName)!}" class="form-control" readonly="readonly">
                                </div>
                                
                                <div align="right"> 
                                <button id="btn-add"  type="submit"  class="btn btn-default">添加项目</button>
                                <button id="btn-submit"  type="submit"  class="btn btn-default">提交订单</button>
                                <button id="btn-cancel" type="button" class="btn btn-default">取消</button>
                                </div>
                                
                                 
                                <div class="form-group">
                                    <label>项目</label>
                                    <select id="projectId"  name="orderformitem.projectId"  class="form-control">
                                    </select>
                                </div>
                                
                                <div class="form-group">
                                    <label>技师</label>
                                    <select id="userId"  name="orderformitem.userId"  class="form-control">
                                    </select>
                                </div>
                                
                                <div class="form-group">
                                    <label>房间</label>
                                    <select id="roomId"  name="orderformitem.roomId"  class="form-control">
                                    </select>
                                </div>
                                
                                </div>
                            </form>   
                        </div>
                    </div>
                </div>
                <!-- /.panel-body -->
       </div>
       <!-- /.panel -->
       
      <script>
      
       $(function() {
    	   
    	   $('#btn-add').click( function () {
    		   var m = 0;
    		   $("#control").val(m);
    		  
    		   $('form').validate({
                   submitHandler : function(form) {
    		               $(form).ajaxSubmit(function(data) {
    		                   if(data.result){
    		                	   parent.layer.msg(data.msg, {time: 1000, icon:1});
    		                	   $("#customerId").attr("readonly","readonly");
    		                	   var n = -1;
    		                	   $("#projectId").val(n);
    		                	   $("#userId").val(n);
    		                   }else{
    		                	   parent.layer.msg(data.msg, {time: 1000, icon:2});	
    		                   }
    		                   
    		               });
                   } 
               });
    		   
    	   });   
    	  
    	   
    	   
    	   $('#btn-submit').click( function () {
    		   var m = 1;
    		   $("#control").val(m);
    		   $('form').validate({
                   submitHandler : function(form) {
    		               $(form).ajaxSubmit(function(data) {
    		            	   
    		                   if(data.result){
    		                	   parent.layer.msg(data.msg, {time: 1000, icon:1});
    		                	   
    		                   }else{
    		                	   parent.layer.msg(data.msg, {time: 1000, icon:2});
    		                	   
    		                   }
    		                   
    		               });
                   } 
               });
    		   var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        	   parent.layer.close(index); 
    	   });
    	   
    	   
    	   $('#btn-cancel').click( function () {
    		   var m = 2;
    		   $("#control").val(m);
    		   var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
        	   parent.layer.close(index);
        	   parent.layer.msg('订单已取消', {time: 1000, icon:5});
    		   
    		   
    	   });
    	   
           initSelector1();
           initSelector2();
           initSelector3();
           initSelector4();
           
           
       });
       
       
       function initSelector1(){
      	    var selector=  $("#customerId");
      		 selector.append("<option value='-1'>选择客户</option>"); 
      		 <#list customer as c>  //freemarker遍历用法
      		 var customerName="${c.customerName}";
      		 var id = "${c.customerId}";
      		 selector.append("<option value='"+id+"'>"+customerName+"</option>");
      		 </#list>
      		selector.val(${(orderform.customerId)!}); 
         }
       
       function initSelector2(){
     	    var selector=  $("#projectId");
     		 selector.append("<option value='-1'>选择项目</option>"); 
     		 <#list project as p>  //freemarker遍历用法
     		 var projectName="${p.projectName}";
     		var projectPrice="${p.projectPrice}";
     		 var id = "${p.projectId}";
     		 selector.append("<option value='"+id+"'>"+projectName+" "+projectPrice+"元"+"</option>");
     		 </#list>
     		selector.val(${(orderformitem.projectId)!}); 
        }
       
       function initSelector3(){
     	    var selector=  $("#userId");
     		 selector.append("<option value='-1'>选择技师</option>"); 
     		 <#list user as u>  //freemarker遍历用法
     		 var userName="${u.userName}";
     		 var id = "${u.userId}";
     		 selector.append("<option value='"+id+"'>"+userName+"</option>");
     		 </#list>
     		selector.val(${(orderformitem.userId)!}); 
        }
       
       function initSelector4(){
    	    var selector=  $("#roomId");
    		 selector.append("<option value='-1'>选择房间</option>"); 
    		 <#list room as r>  //freemarker遍历用法
    		 var roomNumber="${r.roomNumber}";
    		 var id = "${r.roomId}";
    		 selector.append("<option value='"+id+"'>"+roomNumber+"</option>");
    		 </#list>
    		selector.val(${(orderformitem.roomId)!}); 
       }
       
       
       
       
    </script>
    </body>
</html>    	 
    	 
    	 
    	 
    	 
    	 
    	 
    	   

